(*
Source file: BasicMain.fs
October, 2012
Authors:	Jorge Fabian Maciel Hernandez	967153
		Esteban Perez Mejia		1163982

*)

open BASICUtils
open BASICSemantic
open BASICCodeGenerator
 
[<EntryPoint>]
let main (args : string[]) =        
    try
        if args.Length <> 2 then
            failwith "Please specify input and output file names." 
        
        let parseTree = parseFile args.[0]
        printfn "Syntax OK"
        printf "%A\n" parseTree
        
        let scalarTable, arrayTable, matrixTable, defFunctions, dataList = semanticAnalysis parseTree
        printfn "Semantics OK"
        printfn "Scalar Variable Table: %A" scalarTable
        printfn "Array Variable Table: %A" arrayTable
        printfn "Matrix Variable Table: %A" matrixTable
        printfn "Function Definition Table: %A" defFunctions
        
        let code = generateCode (scalarTable, arrayTable, matrixTable, defFunctions) dataList parseTree
        writeFile args.[1] code
        printfn "CIL Code generated"
        
    with
        | Failure(msg) ->
            printfn "%s" msg
        | e -> 
            printfn "%s" e.Message
    0
